package me.ezitku.base.ShapeViews

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.os.Build
import androidx.annotation.RequiresApi
import android.util.AttributeSet
import android.widget.Button
import android.widget.TextView
import me.ezitku.base.R

/**
 * Created by yurqi on 2018/3/7.
 * QQ: 906120575 | Wechat : kalip008
 * Tashkin Company
 */

@SuppressLint("AppCompatCustomView")
open class ShapeTextView : TextView {
    //Normal
    var _radius = 0f

    var _stroke_width = 0
    var _stroke_color = 0

    var _dash_width = 0F
    var _dash_gap = 0F

    var _solid_color = 0

    var _text_color = 0

    //Press
    var _press_radius = 0f

    var _press_stroke_width = 0
    var _press_stroke_color = 0

    var _press_dash_width = 0F
    var _press_dash_gap = 0F

    var _press_solid_color = 0

    var _press_text_color = Color.parseColor("#000000")


    //Select
    var _select_radius = 0f

    var _select_stroke_width = 0
    var _select_stroke_color = 0

    var _select_dash_width = 0F
    var _select_dash_gap = 0F

    var _select_solid_color = 0

    var _select_text_color = Color.parseColor("#000000")

    constructor(context: Context) : super(context) {
        init()
    }

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
        initAttrs(attrs)
        init()
    }

    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
        init()
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
        init()
    }


    fun initAttrs(attrs: AttributeSet) {
        val attr = context.obtainStyledAttributes(attrs, R.styleable.ShapeView)

        //      Normal
        _radius = attr.getDimension(R.styleable.ShapeView_radius, 0f)

        _stroke_width = attr.getInt(R.styleable.ShapeView_stroke_width, 0)
        _stroke_color = attr.getColor(R.styleable.ShapeView_stroke_color, 0)

        _dash_width = attr.getFloat(R.styleable.ShapeView_dash_width, 0f)
        _dash_gap = attr.getFloat(R.styleable.ShapeView_dash_gap, 0f)

        _solid_color = attr.getColor(R.styleable.ShapeView_solid_color, 0)

        _text_color = attr.getColor(R.styleable.ShapeView_text_color,0)

//        Press
        _press_radius = attr.getDimension(R.styleable.ShapeView_press_radius, _radius)

        _press_stroke_width = attr.getInt(R.styleable.ShapeView_press_stroke_width, _stroke_width)
        _press_stroke_color = attr.getColor(R.styleable.ShapeView_press_stroke_color, _stroke_color)

        _press_dash_width = attr.getFloat(R.styleable.ShapeView_press_stroke_width, _dash_width)
        _press_dash_gap = attr.getFloat(R.styleable.ShapeView_press_stroke_color, _dash_gap)

        _press_solid_color = attr.getColor(R.styleable.ShapeView_press_solid_color, _solid_color)

        _press_text_color = attr.getColor(R.styleable.ShapeView_press_text_color, _text_color)



        //        Select
        _select_radius = attr.getDimension(R.styleable.ShapeView_select_radius, _radius)

        _select_stroke_width = attr.getInt(R.styleable.ShapeView_select_stroke_width, _stroke_width)
        _select_stroke_color = attr.getColor(R.styleable.ShapeView_select_stroke_color, _stroke_color)

        _select_dash_width = attr.getFloat(R.styleable.ShapeView_select_stroke_width, _dash_width)
        _select_dash_gap = attr.getFloat(R.styleable.ShapeView_select_stroke_color, _dash_gap)

        _select_solid_color = attr.getColor(R.styleable.ShapeView_select_solid_color, _solid_color)

        _select_text_color = attr.getColor(R.styleable.ShapeView_select_text_color, _text_color)

        init()
    }

    fun init() {
        Background {
            selected {
                radius = _select_radius

                strokeWidth = _select_stroke_width
                strokeColor = _select_stroke_color

                dashWidth = _select_dash_width
                dashGap = _select_dash_gap

                color = _select_solid_color

                textColor = _select_text_color
            }

            press {
                radius = _press_radius

                strokeWidth = _press_stroke_width
                strokeColor = _press_stroke_color

                dashWidth = _press_dash_width
                dashGap = _press_dash_gap

                color = _press_solid_color

                textColor = _press_text_color
            }

            normal {
                radius = _radius

                strokeWidth = _stroke_width
                strokeColor = _stroke_color

                dashWidth = _dash_width
                dashGap = _dash_gap

                color = _solid_color

                textColor = _text_color
            }
        }
    }

}